<template>
	<view>
		<u--input placeholder="请输入内容" border="surround" v-model="scanResult"></u--input>
		<u-button type="primary" text="扫码" @click="callScan"></u-button>

		<u-notify ref="uNotifyRef"></u-notify>
	</view>
</template>

<script>
	const App = getApp();
	//引入vue
	import Vue from "vue";
	import store from "@/store";
	//必须实例化
	var vm = new Vue();

	export default {
		components: {
			// RadioGroup,
		},
		data() {
			return {
				scanResult: '',

			};
		},

		/**
		 * 生命周期函数--监听页面加载
		 */
		onLoad(options) {
			// 当前页面参数
			// this.initEmitMonitor();
			//初始化

			window.callScanBack = this.callScanBack;
			window.test = this.test;



		},

		/**
		 * 生命周期函数--监听页面显示
		 */
		onShow() {
			// this.scanCodeFun(); 
		},
		/**
		 * 生命周期函数--监听页面显示
		 */
		methods: {
			//调用原生红外
			callScan() {
				window.android.callScan();
				this.$refs.uNotifyRef.show({
					top: 10,
					type: 'primary',
					message: '调用原生红外',
					duration: 1000 * 2,
					safeAreaInsetTop: true
				})
			},
			//扫码数据回调
			callScanBack(res) {
				console.log('扫码数据回调----->', res);
				if (typeof res === 'string') {
					try {
						let result = {};
						result = JSON.parse(res);
						console.log('扫码数据回调----->', result);
						if (result.status_code === 200 && result.code) {
							this.$refs.uNotifyRef.show({
								top: 10,
								type: 'primary',
								message: `扫码结果 ${result}`,
								duration: 1000 * 2,
								safeAreaInsetTop: true
							})
						} else if (result.status_code === 204) {
							this.$refs.uNotify.warning('请重新扫码！');
						}
					} catch (err) {
						//TODO handle the exception
						this.$refs.uNotify.warning('扫码错误请重新扫码！');
					}
				}
				uni.hideLoading();
			},
		},

		/**
   * 
''   * 下拉刷新
   */
		onPullDownRefresh() {},

		/**
		 * 分享当前页面
		 */
		onShareAppMessage() {},

		/**
		 * 分享到朋友圈
		 * 本接口为 Beta 版本，暂只在 Android 平台支持，详见分享到朋友圈 (Beta)
		 * https://developers.weixin.qq.com/miniprogram/dev/framework/open-ability/share-timeline.html
		 */
		onShareTimeline() {},
	};
</script>

<style lang="scss" scoped>

</style>